angular.module('fs.waf').controller('poi.demo.fsCheckboxGroupController', [
  '$scope',
  '$q',
  function($scope, $q) {
    var config = {
      name: 'checkbox-group',
      size: 4,
      showStyle: 'edit',
      type: 'checkbox-group',
      model: 'checkboxGroupValue',
      appScope: $scope,
      tooltip: 'checkbox-group tooltip',
      options: {
        groups: [
          {
            // isCollapsed: false,
            // showHeadCheckbox: true,
            // allChecked: false,
            title: 'fsCheckboxGroup',
            data: [
              {
                display: 'Jack',
                value: 123,
                desc: 'welcome Jack'
              },
              {
                display: 'Lee',
                value: 456,
                desc: 'welcome Lee'
              }
            ]
          }
        ]
      }
    };

    var ctrl = this;

    ctrl.ngModel = {};

    ctrl.layoutConfig = {
      demo: {
        name: 'demo',
        gridGroups: [
          {
            grids: ['edit', 'readonly', 'view']
          },
          {
            grids: ['optionsDataIsString', 'displayText', 'valueText', 'descText', 'changeData']
          },
          {
            grids: ['isCollapsed_true', 'isCollapsed_false']
          },
          {
            grids: ['showHeadCheckbox_true', 'showHeadCheckbox_false']
          },
          {
            grids: ['allChecked_true', 'allChecked_false']
          },
          {
            grids: ['allChecked_true2']
          }
        ],
        gridConfigs: {
          valueText: {
            name: 'text',
            label: 'value',
            size: 2,
            type: 'text',
            model: 'textValue',
            appScope: $scope,
            showStyle: 'edit',
            tooltip: 'value'
          },
          displayText: {
            name: 'text',
            label: 'display',
            size: 2,
            type: 'text',
            model: 'displayText',
            appScope: $scope,
            showStyle: 'edit',
            tooltip: 'display',
            uppercase: false
          },
          descText: {
            name: 'text',
            label: 'descText',
            size: 2,
            type: 'text',
            model: 'descText',
            appScope: $scope,
            showStyle: 'edit',
            tooltip: 'display',
            uppercase: false
          },
          changeData: {
            name: 'button',
            label: 'changeData',
            size: 2,
            type: 'button',
            appScope: $scope,
            text: 'Add Data',
            tooltip: 'button tooltip',
            options: {
              icon: 'setup',
              showIcon: false,
              callback: {
                click: 'vm.changeData'
              }
              // hotKey: 'alt+1'
            }
          },
          edit: {
            name: 'checkbox-group',
            label: 'edit',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              // callback: {
              //   changed: 'changedFunc'
              // },
              groups: [
                {
                  isCollapsed: false,
                  showHeadCheckbox: true,
                  allChecked: false,
                  title: 'fsCheckboxGroup',
                  data: 'vm.normalData'
                }
              ]
            }
          },
          readonly: {
            name: 'checkbox-group',
            label: 'readonly',
            size: 4,
            showStyle: 'readonly',
            type: 'checkbox-group',
            model: 'checkboxGroupValue',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              // callback: {
              //   changed: 'changedFunc'
              // },
              groups: [
                {
                  isCollapsed: false,
                  showHeadCheckbox: true,
                  allChecked: false,
                  title: 'fsCheckboxGroup',
                  data: 'vm.normalData'
                }
              ]
            }
          },
          view: {
            name: 'checkbox-group',
            label: 'view',
            size: 4,
            showStyle: 'view',
            type: 'checkbox-group',
            model: 'checkboxGroupValue',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              // callback: {
              //   changed: 'changedFunc'
              // },
              groups: [
                {
                  isCollapsed: false,
                  showHeadCheckbox: true,
                  allChecked: false,
                  title: 'fsCheckboxGroup',
                  data: 'vm.normalData'
                }
              ]
            }
          },
          optionsDataIsString: {
            name: 'checkbox-group',
            label: 'optionsDataIsString',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              // callback: {
              //   changed: 'changedFunc'
              // },
              groups: [
                {
                  isCollapsed: false,
                  showHeadCheckbox: true,
                  allChecked: false,
                  title: 'fsCheckboxGroup',
                  data: 'vm.normalData'
                }
              ]
            }
          },
          isCollapsed_true: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue11',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  isCollapsed: true,
                  title: 'isCollapsed_true',
                  data: [
                    {
                      display: 'Jack',
                      value: 123,
                      desc: 'welcome Jack'
                    },
                    {
                      display: 'Lee',
                      value: 456,
                      desc: 'welcome Lee'
                    }
                  ]
                }
              ]
            }
          },
          isCollapsed_false: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue12',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  isCollapsed: false,
                  title: 'isCollapsed_false',
                  data: [
                    {
                      display: 'Jack',
                      value: 123,
                      desc: 'welcome Jack'
                    },
                    {
                      display: 'Lee',
                      value: 456,
                      desc: 'welcome Lee'
                    }
                  ]
                }
              ]
            }
          },
          showHeadCheckbox_true: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue21',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  showHeadCheckbox: true,
                  title: 'showHeadCheckbox_true',
                  data: [
                    {
                      display: 'Jack',
                      value: 123,
                      desc: 'welcome Jack'
                    },
                    {
                      display: 'Lee',
                      value: 456,
                      desc: 'welcome Lee'
                    }
                  ]
                }
              ]
            }
          },
          showHeadCheckbox_false: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue22',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  showHeadCheckbox: false,
                  title: 'showHeadCheckbox_false',
                  data: [
                    {
                      display: 'Jack',
                      value: 123,
                      desc: 'welcome Jack'
                    },
                    {
                      display: 'Lee',
                      value: 456,
                      desc: 'welcome Lee'
                    }
                  ]
                }
              ]
            }
          },
          allChecked_true: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue31',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  showHeadCheckbox: true,
                  allChecked: true,
                  title: 'allChecked_true',
                  data: 'vm.normalData'
                }
              ]
            }
          },
          allChecked_true2: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue312',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: 'vm.options'
          },
          allChecked_false: {
            name: 'checkbox-group',
            size: 4,
            showStyle: 'edit',
            type: 'checkbox-group',
            model: 'checkboxGroupValue32',
            appScope: $scope,
            tooltip: 'checkbox-group tooltip',
            options: {
              groups: [
                {
                  showHeadCheckbox: true,
                  allChecked: false,
                  title: 'allChecked_false',
                  data: 'vm.normalData'
                }
              ]
            }
          }
        }
      }
    };

    ctrl.options = {
      groups: [
        {
          showHeadCheckbox: true,
          allChecked: true,
          title: 'allChecked_true',
          data: 'vm.normalData'
        }
      ]
    };

    ctrl.normalData = [
      {
        display: 'Jack',
        value: 123,
        desc: 'welcome Jack'
      },
      {
        display: 'Lee',
        value: 456,
        desc: 'welcome Lee'
      }
    ];

    ctrl.componentStyle = [
      {
        value: 'edit',
        display: 'edit'
      },
      {
        value: 'readonly',
        display: 'readonly'
      },
      {
        value: 'view',
        display: 'view'
      }
    ];

    ctrl.changeData = function() {
      if (ctrl.ngModel.textValue && ctrl.ngModel.displayText) {
        ctrl.normalData.push({
          value: ctrl.ngModel.textValue,
          display: ctrl.ngModel.displayText,
          desc: ctrl.ngModel.descText
        });
      }
    };

    ctrl.clickFun = function() {
      console.log(ctrl.ngModel.linkValue);
    };
  }
]);
